package com.github_dididipapa.mall.product.web;

import com.github_dididipapa.mall.product.entity.CategoryEntity;
import com.github_dididipapa.mall.product.service.CategoryService;
import com.github_dididipapa.mall.product.vo.CatelogTreeVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @description: 视图控制器
 * @author: dididi_papa
 * @email: mitis1624087624@gmail.com
 * @date: 2025/07/07  11:58
 */
@RequiredArgsConstructor
@Controller
public class indexController {

    private final CategoryService categoryService;
    @GetMapping({"/", "/index.html"})
    public String index(Model  model) {
        List<CategoryEntity> categoryEntities = categoryService.getLevelOneClassOfProduct();
        model.addAttribute("categories", categoryEntities);
        return "index";
    }

    @ResponseBody
    @GetMapping("/index/catelog.json")
    public Map<String, List<CatelogTreeVo>> getCatelogJson() {
        return categoryService.getCatelogJson();
    }
}
